module StateMachine
  def self.included(base)
    base.extend ClassMethods
  end
  module ClassMethods
    def acts_as_machine
      has_many :machines,:as=>:mechanical

      class_eval <<-EOV
      include StateMachine::InstanceMethods
      def self.state_machines
      @state_machines||=Machine.find(:all,:conditions=>"mechanical_type='User'")
      end
        
      def self.state_machines_hash
      @state_machine_hash||=machines.collect{|machine|{machine.name=>machine}}
      end
        
      def self.state_machine(name,options={})
      state_machines_hash[name]
      end
      EOV
    end
  end
  
  module InstanceMethods

  end
end